package com.huc.example.config;

import com.huc.example.properties.ProjectProperty;
import com.huc.example.service.ProjectService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author huc
 * @version 1.0
 * @note
 * @date 2021/9/18 9:52
 */
@ConditionalOnProperty(
        prefix = "project",
        value = "name",
        matchIfMissing = true
)
@Configuration
@EnableConfigurationProperties(ProjectProperty.class)
public class ProjectConfig {
    @Autowired
    private ProjectProperty projectProperty;

    @Bean(name = "projectService")
    public ProjectService projectService() {
        return new ProjectService(projectProperty.getName(), projectProperty.getUrl());
    }

}
